package com.itheima.demo.duotaiDemo;


/*
*    1. 多态的前提：
*           * 要有(继承/实现)关系
*           * 要有方法的重写
*           * 要有父类引用指向子类对象 —— 父类 对象名 = new 子类();
*
* */


public class Test {
    public static void main(String[] args) {
        Animal animal = new Dog();
        Animal animal1 = new Cat();

        animal.eat();
        System.out.println(animal.str);

        animal1.eat();
        System.out.println(animal1.str);

        Fu f = new Zi();
        f.name();
        System.out.println(f.I);

    }
}


class Animal{
    String str = "我是动物";
    public void eat(){
        System.out.println("动物喝水");
    }
}

class Dog extends Animal{
    String str = "我是狗";
    @Override
    public void eat() {
        System.out.println("狗狗喝水");
    }
}

class Cat extends Animal{
    String str = "我是猫";
    @Override
    public void eat() {
        System.out.println("猫猫喝水");
    }
}

interface Fu{
    int I = 10;
    void name();
}

class Zi implements Fu{
    int i  = 20 ;
    @Override
    public void name() {
        System.out.println("我叫AAA");
    }
}

